﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace _1.OrderService
{
    public partial class ModifyForm : Form
    {
        Form1 _form1;
        OrderService _orderService;
        public ModifyForm(Form1 form1,OrderService orderService)
        {
            InitializeComponent();
            _form1 = form1;
            _orderService = orderService;
        }

        private void ModifyForm_Load(object sender, EventArgs e)
        {

        }

        private void button_quit_Click(object sender, EventArgs e)
        {
            _form1.Show();
            this.Close();
        }

        private bool IsNumber(string s)
        {
            if (string.IsNullOrWhiteSpace(s)) return false;
            const string pattern = "^[0-9]*$";
            Regex rx = new Regex(pattern);
            return rx.IsMatch(s);
        }

        private void button_modify_Click(object sender, EventArgs e)
        {
            string idString = textBox1.Text;
            if (!IsNumber(idString))
            {
                DialogResult dr = MessageBox.Show("订单单号输入不合法请重新输入", "警告", MessageBoxButtons.OK);
                textBox1.Text = "";
                return;
            }
            long orderID = Convert.ToInt64(idString);
            if(!_orderService.isHaveOrder(orderID))
            {
                DialogResult dr = MessageBox.Show("订单不存在", "警告", MessageBoxButtons.OK);
                textBox1.Text = "";
                return;
            }
            ModifyDetailForm modifyDetailForm = new ModifyDetailForm(this, _orderService, orderID);
            modifyDetailForm.Show();
            this.Hide();
        }
    }
}
